package leihua.crm.workbench.web.controller;

import leihua.crm.commons.contants.Contants;
import leihua.crm.commons.domain.ReturnObject;
import leihua.crm.workbench.domain.Contacts;
import leihua.crm.workbench.domain.Customer;
import leihua.crm.workbench.service.ContactsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

/**
 * @Author leiHua
 * @Date 2022/10/28 14:20
 */
@Controller
public class ContactsController {
    @Autowired
    ContactsService contactsService;

    @RequestMapping("/workbench/contacts/index.do")
    public String index(){
        return "workbench/contacts/index";
    }

    @RequestMapping("/workbench/customer/queryContactsForPageByCondition.do")
    @ResponseBody
    public  Object queryCustomerForPageByCondition(String fullname,String owner,String source ,String customerName,int pageSize,int pageNo){

        int beginNo=(pageNo-1)*pageSize;
        HashMap<String, Object> map = new HashMap<>();
        map.put("fullname",fullname);
        map.put("owner",owner);
        map.put("source",source);
        map.put("customerName",customerName);
        map.put("pageSize",pageSize);
        map.put("beginNo",beginNo);
        HashMap<String, Object> data = new HashMap<>();
        try {
            List<Contacts> contactsList = contactsService.queryContactsForPageByCondition(map);
            int totalRows = contactsService.queryCountOfContactsByCondition(map);

            data.put("contactsList",contactsList);
            data.put("totalRows",totalRows);
            data.put("code","1");
        } catch (Exception e) {
            e.printStackTrace();
            data.put("code",'0');
        }
        return  data;

    }
}
